package com.systop.dxjj.modules.student.service.impl;

import com.systop.dxjj.common.pojo.Student;
import com.systop.dxjj.common.pojo.StudentUser;
import com.systop.dxjj.common.pojo.TeacherUser;
import com.systop.dxjj.modules.student.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service("studentUserDetailsService")
public class StudentUserDetailsService implements UserDetailsService {
    @Autowired
    StudentMapper studentMapper;

    //加载用户

    public UserDetails loadUserByUsername(String studentphone) throws UsernameNotFoundException {
        //调用studentMapper方法，根据用户名查询数据库
        Student student = studentMapper.selectByPhone(studentphone);
        //判断
        if(student == null){
            throw new UsernameNotFoundException("用户名不存在！");
        }


        //把数据封装成UserDetails返回
        return new StudentUser(student);
    }
}
